<?php
/**************************************************/
## Class Name - Model_Background_Images (Contains all the functions related to invites users)
## Created By - Techmodi (25/06/2011)
/**************************************************/

class Model_Background_Images extends Database 
{	
	//Constructor
	function Model_Background_Images() {
		$this->image = "getbids_logo";
		$this->Database();
	}
	
	//Add background image in database
	function addBackgroundImage($imageArray) {
		$this->InsertData( $this->image , $imageArray );		
		$insertId = mysql_insert_id();
		return $insertId;
	}	
	
	//Edit background image by imageid
	function editBackgroundImage($imageArray, $Id){
		$this->UpdateData($this->image,$imageArray,"image_id",$Id,0);
	}
	
	//Delete background image by imageid
	function deleteBackgroundImage($id){
		$this->DeleteData($this->image,"image_id",$id);
	}
	
	//Function to get all added images
	function getAllImages($search='',$limit='',$offset=0) {
		$fields = array();	
		$tables = array($this->image);
		$where  = array();
		if($search != '' && $search != 'Image Name') {
			$where[] = "image_name LIKE '%".$search."%'";
		}
			
		$sql    = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(), $limit,$offset,0);
		$result = $this->FetchAll($sql); 
		return $result;
	}
	
	//Function to get image details by id
	function getImageDetails($imageId) {
		$fields = array();	
		$tables = array($this->image);
		$where  = array("image_id = '".$imageId."'");
		$sql    = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(), $limit='',$offset=0,0);
		$result = $this->FetchRow($sql); 
		return $result;
	}
	
	//Function to get count of active images
	function getActiveImageCount() {
		$fields = array("COUNT(image_id) as totalCount");	
		$tables = array($this->image);
		$where  = array("status = '1'");
		$sql    = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(), $limit='',$offset=0,0);
		$result = $this->FetchRow($sql); 
		return $result['totalCount'];
	}
	
	//Get Active image
	function getCurrentActiveImage() {
		$fields = array("image_path");	
		$tables = array($this->image);
		$where  = array("status = '1'");
		$sql    = $this->SelectData($fields,$tables, $where, $order = array("image_id DESC"), $group=array(), $limit=1,$offset=0,0);
		$result = $this->FetchRow($sql); 
		return $result['image_path'];
	}
	
	//Function to update image status
	function updateImageStatus() {
		$query = "UPDATE $this->image SET status = '0'";
		$result = $this->ExecuteQuery($query);
	}
	
	
}
?>